package Sj.sj03;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;

public class Sj01 {
    public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
       ShowPhoneInfo();
    }
    public static void ShowPhoneInfo() {
        Document doc=null;
        try{
            //加载DOM树
            SAXReader saxReader=new SAXReader();
            doc=saxReader.read(new File("src/main/java/Sj/Jd01.xml"));
        }catch (Exception e){
            e.printStackTrace();
        }
        //获取XML的根节点
        org.dom4j.Element root=doc.getRootElement();
        //遍历所有的Brand标签
        for (Iterator itBrand = root.elementIterator(); itBrand.hasNext();){
            org.dom4j.Element brand=(org.dom4j.Element) itBrand.next();
            //输出标签的name属性
            System.out.println("品牌："+brand.attributeValue("name"));
            //遍历Type标签
            for (Iterator itTYpe=brand.elementIterator();itTYpe.hasNext();){
                org.dom4j.Element type=(Element) itTYpe.next();
                //输出标签的name属性
                System.out.println("\t型号："+type.attributeValue("name"));
            }
        }
    }
}
